package com.cn.ryc.mapper;

import com.cn.ryc.model.Staff;
import com.cn.ryc.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    // 根据用户名查询用户信息
    @Select("SELECT * FROM users WHERE username = #{username}")
    User findByUsername(@Param("username") String username);

    @Select("SELECT COUNT(*) > 0 FROM users WHERE username = #{username}")
        // 根据用户名查询用户是否存在
    boolean existsByUsername(@Param("username") String username);

    @Select("SELECT * FROM users WHERE role != '超级管理员'")
    List<User> getAllUser();

    @Insert("INSERT INTO users (username, password, email, phone, role) " +
            "VALUES (#{username}, #{password}, #{email}, #{phone}, #{role})")
        // 插入一个用户信息到数据库中
    void insertUser(User user);

    // 更新用户信息
    @Update("UPDATE users SET username = #{username}, area = #{area}, phone = #{phone}, email = #{email} WHERE id = #{id}")
    void updateUser(User user);

    // 更新用户密码
    @Update("UPDATE users SET password = #{password} WHERE id = #{id}")
    void updatePassword(User user);

    // 根据id查询用户信息
    @Select("SELECT * FROM users WHERE id = #{id}")
    User getUserById(Long id);

    // 重置密码
    @Update("UPDATE users SET password = #{password} WHERE id = #{id}")
    public void resetPassword(User user);
}